<script language="JavaScript" type="text/javascript" src="<tpl> $site_url </tpl>/js/jquery/jquery.ajaxfileupload.js"></script>
<form action="../app/<tpl> $app_module.app_module_sign </tpl>/system.php?action=update" method="post" id="updatesupply" name="updatesupply" style="width:680px; float:left">
	<input type="hidden" name="class_id" id="class_id"  value="<tpl> $supply_array.s_class_id </tpl>" />
	<input type="hidden" name="old_class_id" id="old_class_id" value="<tpl> $supply_array.s_class_id </tpl>" />
    <input type="hidden" name="sid" id="sid" value="<tpl> $supply_array.s_id </tpl>" />
<table width="680" class="from_table" style="width:680px; float:left">
	<tr>
	<th height="40" align="left"><tpl> $langSupplySelClass </tpl>:</th>
		<td height="40" style="padding:5px 0">
        	<div id="pc_id_originality" style=" width:480px"><tpl> $supply_array.s_class_name </tpl><span class="btn_left"><input type="button" id="edit_button" value="<tpl> $langCedit </tpl>" onclick="editstate()" class="btn_submit"/></span>
        	</div>
		    <div id="pc_id_edit" style="display:none">
            <select name="ac1" id="ac1" style="WIDTH: 110px">
            <option value=""></option>
            <tpl> foreach item = parent from = $ProductCateArray </tpl>
            <option value="<tpl>$parent.id</tpl>||<tpl>$parent[5]</tpl>"><tpl>$parent.name</tpl></option>
            <tpl> /foreach </tpl>
            </select>
            <select name="c2" id="c2" style="WIDTH: 110px">
            </select>
            <select name="c3" id="c3" style="WIDTH: 110px">
            </select>
            <select name="c4" id="c4" style="WIDTH: 110px">
            </select>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      </div>
	  <span class="btn_left" id="cancel_edit" style="display:none"> 	<input type="button" id="cancel_edit_button" value="<tpl> $langCCanceledit </tpl>" onclick="canceledit()"  class="btn_submit"/></span>
	 	</td>
	</tr>
    <tr>
    	<th align="left"><tpl> $langSupplySelType </tpl>:</th>
        <td  >
        	<input type="radio" name="radioType" value="1" <tpl> if $supply_array.s_type eq 1 </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langSupplyTypeQiu </tpl>
			<input type="radio" name="radioType" value="2" <tpl> if $supply_array.s_type eq 2 </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langSupplyTypeGone </tpl>
		</td>
    </tr>
    <tr>
    	<th align="left"  ><tpl> $langSupplySelQuality </tpl>:</th>
        <td  >
        	<input type="radio" name="radioQuality" value="1" <tpl> if $supply_array.s_quality eq 1 </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langSupplyQualityOne </tpl>
			<input type="radio" name="radioQuality" value="2" <tpl> if $supply_array.s_quality eq 2 </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langSupplyQualityTwo </tpl> </td>
    </tr>
	
	<tr>
    	<th align="left"  ><tpl> $langSupplyValdate </tpl>:</th>
        <td  >
        	<select name="valdate" id="valdate">
				<option value="1" <tpl> if $supply_array.s_valdate eq 1 or $vadate eq '' </tpl> selected="selected" <tpl> /if </tpl> ><tpl> $langSupplyValdateFiveDay </tpl></option>
				<option value="2" <tpl> if $supply_array.s_valdate eq 2 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateHalfMonth </tpl></option>
				<option value="3" <tpl> if $supply_array.s_valdate eq 3 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateOneMonth </tpl></option>
				<option value="4" <tpl> if $supply_array.s_valdate eq 4 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateOneQuarter </tpl></option>
				<option value="5" <tpl> if $supply_array.s_valdate eq 5 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateNone </tpl></option>
			</select>
		</td>
    </tr>
	<tr>
    	<th align="left"  ><tpl> $langSupplyPrice </tpl>:</th>
        <td  >
        	<input class="txtinput" type="text" id="s_price"  class="textinput"  name="s_price" value="<tpl> if $supply_array.s_price_face eq '2' </tpl><tpl> $supply_array.s_price </tpl><tpl> /if </tpl>" /> 
			<tpl> $langSupplyOr </tpl>
		  	<input type="checkbox" name="s_price_face" <tpl> if $supply_array.s_price_face eq '1' </tpl>checked="checked"<tpl> /if </tpl> id="s_price_face" value="1" /><label for="s_price_face"><tpl> $langSupplyPriceToFace </tpl></label>
			<label style="display:none" for="s_price" class="wrong" metaDone="true" generated="true"></label> 
		</td>
    </tr>
	<tr>
    	<th align="left"  ><tpl> $langSupplyPhone </tpl>:</th>
        <td  >
        	<input class="txtinput" type="text" id="phone"  class="textinput"  name="phone" maxLength=30 value="<tpl> $supply_array.s_phone </tpl>" /> <label style="display:none" for="phone" class="wrong" metaDone="true" generated="true"></label> 
		</td>
    </tr>
	<tr>
    	<th align="left"  >Email:</th>
        <td  >
        	<input class="txtinput" type="text" id="mail"  class="textinput"  name="mail" maxLength=30 value="<tpl> $supply_array.s_email </tpl>" />
			<label style="display:none" for="mail" class="wrong" metaDone="true" generated="true"></label>  
		</td>
    </tr>
	<tr>
    	<th align="left"  >QQ:</th>
        <td  >
        	<input class="txtinput" type="text" id="qq"  class="textinput"  name="qq" maxLength=30 value="<tpl> $supply_array.s_qq </tpl>" />
			<label style="display:none" for="qq" class="wrong" metaDone="true" generated="true"></label>  
		</td>
    </tr>
	<tr>
    	<th align="left"  >MSN:</th>
        <td  >
        	<input class="txtinput" type="text" id="msn"  class="textinput"  name="msn" maxLength=30 value="<tpl> $supply_array.s_msn </tpl>" /> 
			<label style="display:none" for="msn" class="wrong" metaDone="true" generated="true"></label> 
		</td>
    </tr>
	<tr>
    	<th align="left"  >Skype:</th>
        <td  >
        	<input class="txtinput" type="text" id="skype"  class="textinput" name="skype" maxLength=30 value="<tpl> $supply_array.s_skype </tpl>" />
			<label style="display:none" for="skype" class="wrong" metaDone="true" generated="true"></label> 
		</td>
    </tr>
	<tr>
    	<th align="left"  ><tpl> $langSupplyWangwang </tpl>:</th>
        <td  >
        	<input class="txtinput" type="text" id="wangwang"  class="textinput" name="wangwang" maxLength=30 value="<tpl> $supply_array.s_wangwang </tpl>" />
			 <label style="display:none" for="wangwang" class="wrong" metaDone="true" generated="true"></label> 
		</td>
    </tr>
    <tr>
    	<th align="left" ><tpl> $langSupplyTitle </tpl>:</th>
        <td  >
       	<input class="txtinput" type="text" id="supplyTitle"  class="textinput"  name="supplyTitle" maxLength=30 value="<tpl> $supply_array.s_title </tpl>" />        
		<label style="display:none" for="supplyTitle" class="wrong" metaDone="true" generated="true"></label> 
		</td>
    </tr>
	<tr>
    	<th align="left" ><tpl> $langSupplyPicUpload </tpl>:</th>
        <td  >
       	<div style="width:400px">
			<input type="hidden" name="pic_num" id="pic_num" value="<tpl> $supply_pic_num </tpl>"/>
			<input name="txtPpic"  class="searchforminput" type="file"id="txtPpic" size="40"/>
            <span class="btn_left"><input class="btn_submit" type="button" name="buttonUpload" id="buttonUpload" value="<tpl> $langSupplyUpload </tpl>" onclick="return ajaxFileUpload();" /></span>
		  </div>
		  <!--图片名拼字符串，中间以'|'连接-->
            <input type="hidden" name="p_pic" id="p_pic" value="<tpl> $supply_array.s_pic </tpl>" />
            <span class="posttip" style="display:block; margin:10px 0 0; width:400px"><tpl> $langProductPicSize </tpl></span>
				
			<div id="previewImage">
				<ul id="piclist">
				<tpl> foreach item=one from=$supply_array.spic_arr </tpl>
					<li><img src=<tpl> $site_url </tpl>/<tpl> $one </tpl> /><br /><a href='javascript:;' onclick="ajaxFileDel('<tpl> $one </tpl>',this);"><tpl> $errSupplyDel </tpl></a></li>
				<tpl> /foreach </tpl>
			  	</ul>
			</div>		
			<span id="file_pic_loading" style="display:none"><img src="<tpl> $template_dir </tpl>/images/loading.gif" /></span>
		</td>
    </tr>
    <tr>
        <th align="left">信息内容：</th>
        <td>
			<textarea class="shuru-1" name="txtContent" id="txtContent"><tpl> $supply_array.s_content </tpl></textarea>
            <div><tpl> $langSupplyContentRemark </tpl></div>
			<tpl> if $supply_array.s_member_id eq 0 </tpl>
				<input type="hidden" id="anonymous" name="anonymous" value="2" /><tpl> $langSupplyAnonymous </tpl>
			<tpl> else </tpl>
				<input type="checkbox" id="anonymous" name="anonymous" value="2" <tpl> if $supply_array.s_anonymous eq 2 </tpl>checked="checked"<tpl> /if </tpl>/><label for="anonymous"><tpl> $langSupplyAnonymous </tpl></label>
			<tpl> /if </tpl>
		</td>
      </tr>
	<tr>
		<td width="110" align="left"></td>
		<td  ><span class="btn_left"><input type="submit"  id="saveupdate" class="btn_submit" value="<tpl> $langSysCSave </tpl>" /></span>
		<span class="btn_left">  <input type="button" id="butt_list" class="btn_submit" value="<tpl> $langSupplyReturn </tpl>" /></span></td>
	</tr>
</table>
</form>
<script>
function tonext(whos) {
	$(whos).change(
	function(){
		var valarray=$(this).val().split('||');
		$('#class_id').val(valarray[0]);
		if (valarray[1]=='1') {
			$(this).next().attr('disabled','true').html('<option value="" selected="selected"><tpl> $langCDataToLoading </tpl></option>');
			$.get('../member/own_productcate.php',{action:'list',id:valarray[0]},function(data){
				DataArray = data.split("|||");var a='';for (var i = 0; i<DataArray.length-1; i++) {att=DataArray[i].split("||");id=att[0];cla=att[2];a+='<option value="'+id+'||'+cla+'">'+att[1]+((cla=='1')?' ->':'')+'</option>';};
				$(whos).next().removeAttr('disabled').html('<option value="" selected="selected"></option>'+a).nextAll().html('');
				tonext($(whos).next());
			})} else {
				$('#c4').attr('disabled','true');
				$(whos).next().html('').attr('disabled','true');
			};
	})
};
function editstate(){
	document.getElementById('pc_id_originality').style.display = 'none';
	document.getElementById('pc_id_edit').style.display = '';
	document.getElementById('cancel_edit').style.display = '';
}
function canceledit(){
	document.getElementById('pc_id_originality').style.display = '';
	document.getElementById('pc_id_edit').style.display = 'none';
	document.getElementById('cancel_edit').style.display = 'none';
	document.getElementById('class_id').value = document.getElementById('old_class_id').value;
}
$().ready(function() {
	//
	tonext('#ac1');
	//表单验证
	var options_modi = {
		beforeSubmit:  function(){showLoading(showText);},
		success:       function(msg){
						hideLoading();
						showMessage(msg.message,msg.type);
						if(msg.type == '1'){
							ShowDiv = "result_content";
							getPageContent("../app/<tpl> $app_module.app_module_sign </tpl>/system.php?action=ajax_list&curpage=<tpl> $condition.curpage </tpl>&keyword=<tpl> $condition.keyword </tpl>&type=<tpl> $condition.type </tpl>&quality=<tpl> $condition.quality </tpl>&searchcate=<tpl> $condition.searchcate </tpl>&username=<tpl> $condition.username </tpl>&anymous=<tpl> $condition.anymous </tpl>");
						}
					},
		type:      'post',
		dataType:  'json'
	};
	$("#updatesupply").validate({
		errorClass: "wrong",
		rules: {
			class_id: {required:true},
			supplyTitle: {required:true,minlength:2,maxlength:50},
			phone: {required:true,maxlength:50},
			mail: {required:true,email:true,maxlength:50},
			qq: {maxlength:11},
			msn: {email:true,maxlength:50},
			skype: {maxlength:50},
			wangwang: {maxlength:50},
			s_price:{required:true,number:true,min:0.01,max:999999999.99}
		},
		messages: {
			class_id: {required: "<tpl> $errSupplyClassIsEmtpy </tpl>"},
			supplyTitle: {required: "<tpl> $errSupplyTitleIsEmtpy </tpl>",minlength: "<tpl> $errSupplyTitleIsTooShort </tpl>",maxlength: "<tpl> $errSupplyTitleIsTooLong </tpl>"},
			phone: {required:'<tpl> $errSupplyPhoneIsEmpty </tpl>',maxlength: "<tpl> $errSupplyPhoneIsTooLong </tpl>"},
			mail: {required:'<tpl> $errSupplyEmailIsEmpty </tpl>',email: "<tpl> $errSupplyEmailIsWrongFormat </tpl>",maxlength: "<tpl> $errSupplyEmailIsTooLong </tpl>"},
			qq: {maxlength: "<tpl> $errSupplyQQIsTooLong </tpl>"},
			msn: {email: "<tpl> $errSupplyMSNIsWrongFormat </tpl>",maxlength: "<tpl> $errSupplyMSNIsTooLong </tpl>"},
			skype: {maxlength: "<tpl> $errSupplySkypeIsTooLong </tpl>"},
			wangwang: {maxlength: "<tpl> $errSupplyWangwangIsTooLong </tpl>"},
			s_price:{required:"<tpl> $errSupplyPriceIsEmpty </tpl>",number:"<tpl> $errSupplyPriceIsNotNumber </tpl>",min:"<tpl> $errSupplyPriceIsMin </tpl>0.01",max:"<tpl> $errSupplyPriceIsMax </tpl>999999999.99"}
		},
		submitHandler: function() {
			$('#updatesupply').ajaxSubmit(options_modi);
		}
	});
});
//返回列表
$("#butt_list").click(function(){
	ShowDiv = "result_content";
	getPageContent("../app/<tpl> $app_module.app_module_sign </tpl>/system.php?action=ajax_list&curpage=<tpl> $condition.curpage </tpl>&keyword=<tpl> $condition.keyword </tpl>&type=<tpl> $condition.type </tpl>&quality=<tpl> $condition.quality </tpl>&class_id=<tpl> $condition.class_id </tpl>&username=<tpl> $condition.username </tpl>&anymous=<tpl> $condition.anymous </tpl>");
});
//多图片上传操作
function ajaxFileUpload()
{
	$("#file_pic_loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	
	//如果图片数量超过3 则返回信息，不允许添加
	if($("#pic_num").val() >= 3){
		alert("<tpl> $errSupplyImageIsBeyong </tpl>:3");
		return false;
	}
	
	$.ajaxFileUpload
	(
		{
			url:'../app/<tpl> $app_module.app_module_sign </tpl>/index.php?action=pic_add',
			secureuri:false,
			fileElementId:'txtPpic',
			dataType: 'json',
			success: function (data, status)
			{
				if(typeof(data.type) != 'undefined')
				{
					if(data.type != '0')
					{
						$("#previewImage ul").append("<li>"+"<img src=<tpl> $site_url </tpl>/"+data.message+" /><br /><a href='javascript:;' onclick=ajaxFileDel(\'"+data.message+"\',this);><tpl> $errSupplyDel </tpl></a></li>");
						if($('#p_pic').val() == ''){
							$('#p_pic').val(data.message);
						}else{
							$('#p_pic').val($('#p_pic').val()+'|'+data.message);
						}
						//图片数量+1
						$("#pic_num").val(parseInt($("#pic_num").val())+1);
					}
				}
			},
			error: function (data, status, e)
			{
				alert('<tpl> $errSupplyUploadPicIsFail </tpl>');
			}
		}
	)
	return false;
}

//删除图片 缩略图名称
function ajaxFileDel(pic_url,obj){
	$.ajax({
		url: "../app/<tpl> $app_module.app_module_sign </tpl>/index.php",
		data: 'action=pic_del&pic_name='+pic_url,
		type:'post',
		dataType:"json",
		success: function(msg){
			if(msg.type == '0'){
				alert(msg.message);
			}else{
				$(obj).parents("li").remove();
				arr = $('#p_pic').val().split('|');
				for(i=0;i<arr.length;i++){
					if(arr[i] == pic_url){
						delete(arr[i]);
					}
				}
				$('#p_pic').val(arr.join('|'));
				//图片数量-1
				$("#pic_num").val(parseInt($("#pic_num").val())-1);
			}
		}
	});
	return false;
}
</script>